<template>
  <div
    class="btn"
    @click="btnFn"
    :class="{
      primary: type === 'primary',
      danger: type === 'danger',
    }"
  >
    <slot>按钮</slot>
  </div>
</template>

<script>
export default {
  props: {
    // 从父组件传过来的变量
    type: String,
  },
  methods: {
    btnFn(e) {
      // 触发父组件的自定义对象
      // 相当于console.log()
      this.$emit("click", e);
    },
  },
};
</script>

<style lang="less" scoped>
.btn {
  width: 300px;
  height: 50px;
  border-radius: 24px;
  background-color: #ccc;
  color: #666;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  margin: 20px auto;
}
.primary {
  background-color: green;
  color: #fff;
}
.danger {
  background-color: red;
  color: #fff;
}
</style>